<?php

class Core_Backend_Component_Ebook_View_Index_Create extends Core_Backend_Share_View_Form {
    
    protected function initialize(){
    	parent::initialize();
    	$this->setTemplatePath('edit');
    }

    protected function buildToolbar($toolbar) {
    	$group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('ebook/index/index'), $this->__('share.button.back'));
        $group = $toolbar->createGroup('save');
        if($this->getIdentity()->isAllowAction('ebook_edit')){
	        $group->addButton($this->__('share.button.submit'))
	        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(array('status'=>'pending'), 'save')."')");
	        $group->addButton($this->__('share.button.save'))
	        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(array('status'=>'draft'), 'save')."')");
        }
        parent::buildToolBar($toolbar);
    }

    protected function buildForm($form) {
        $entity = $this->getModel(NULL);
        $form->setAction($this->getUrl())
                ->setId('ebook_form')
                ->addHiddenField('id', 'ebook[id]');
        $form->addTextboxField($this->__('share.label.title'), 'title', 'ebook[title]', TRUE)->addRequiredRule();
        $form->addTextboxField($this->__('media.label.sd_url'), 'sd_url', 'ebook[sd_url]', TRUE)
                ->addUrlRule()
                ->addRequiredRule();
        $form->addTextboxField($this->__('share.label.tag'), 'tag', 'ebook[tag]');
        if($this->getIdentity()->isAllowAction('ebook_encrypt')){
	        $form->addBooleanField($this->__('media.label.access_limit'), 'access_limit', 'ebook[access_limit]', TRUE)
	                ->setValue(0)
	                ->addRequiredRule();
	        $form->addTextboxField($this->__('media.label.hd_url'), 'hd_url', 'ebook[hd_url]')
	                ->addUrlRule()
	                ->addRequiredRule();
	        $form->addTextboxField($this->__('media.label.limit_times'), 'limit_times', 'ebook[limit_times]');
	        $form->addTextboxField($this->__('media.label.access_password'), 'access_password', 'ebook[access_password]');
        }
        if (!is_null($entity)) {
            $form->bindData($entity->getAllData());
        }
        parent::buildForm($form);
    }

}